import Base from 'models/base';

import SystemUtil from 'utils/systemUtil';

export default class MyCouponData extends Base {
  constructor(coupon) {
    super();

    this.keyId = SystemUtil.getId();
    this.id = coupon.coupon_id;
    this.stockId = coupon.stock_id;
    this.shopName = coupon.shop_name;
    this.description = coupon.description;
    this.headImg = coupon.head_img;
    this.status = coupon.status;

    let branchId = coupon.branch_id;
    if (branchId === undefined) {
      branchId = null;
    }
    this.branchId = branchId;

    let partnerId = coupon.partner_id;
    if (partnerId === undefined) {
      partnerId = null;
    }
    this.partnerId = partnerId;

    let info = coupon.normal_coupon_information;
    let money = info.coupon_amount;
    this.money = money / 100;

    let fullMoney = info.transaction_minimum;
    this.fullMoney = fullMoney / 100;
  }

  getShopData() {
    let partnerId = this.partnerId;
    if (partnerId !== null) {
      return {
        partnerId
      };
    }

    return {
      branchId: this.branchId
    };
  }
}
